{% from 'components/field.html' import render_field %}

{% extends "layout.html" %}

{% block title %}
    Edit User - {{ user.username }}
{% endblock %}

{% block header %}
    <ol class="breadcrumb">
        <li><a href="{{ url_for('.list') }}">Admin</a></li>
        <li><a href="{{ url_for('.list') }}">Users</a></li>
        <li class="active">Edit User</li>
    </ol>
{% endblock %}

{% block body %}
    <form method="POST" action="{{ request.url }}">
        <div class="panel panel-default">
            <div class="panel-heading">
                Edit User
            </div>
            <div class="panel-body">
                {{ form.csrf_token }}
                {{ render_field(form.username) }}
                {{ render_field(form.email) }}
                <div class="checkbox">
                    <label>
                        {{ form.is_admin() }}
                        {{ form.is_admin.label.text }}
                    </label>
                </div>
                <div class="checkbox">
                    <label>
                        {{ form.active() }}
                        {{ form.active.label.text }}
                    </label>
                </div>
            </div>
            <div class="panel-footer">
                <button type="submit" class="btn btn-default"><i class="fa fa-floppy-o"></i> Save</button>
                <a class="btn btn-default" href="{{ url_for('.list') }}"><i class="fa fa-times"></i> Cancel</a>
                {% if current_user.is_admin and not user == current_user %}
                    {% set dialogue = 'Are you sure you want to delete %s?' % user.username %}
                    <a data-confirm data-dialogue="{{ dialogue }}" class="btn btn-default pull-right" href="{{ url_for('.delete', id=user.id) }}">
                        <i class="fa fa-trash"></i> Delete
                    </a>
                {% endif %}
            </div>
        </div>
    </form>
{% endblock %}

{% block footer %}
{% endblock %}
